<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ui" uri="http://com.am.tag" %>
<%@ include file="../common.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'dictionaryEdit.jsp' starting page</title>
    <script type="text/javascript">
	   
    	$().ready(function(){
    		
    		var id = "${param.id}";
    		if(id != "")
    		{
	    		ajax.remoteCall("com.system.dao.DictionaryDao:getDictionary",[id],function(reply){
					Form.bindForm("winForm",reply.getResult());
	    		});
    		}
    	});
    	
    	
    	function doCheck()
    	{
    		if($.trim($("#value").val()) == "")
    		{
    			alert("数据项的值不能为空");
    			return false;
    		}
    		
    		if($.trim($("#code").val()) != "" && !check_alpha($.trim($("#code").val())))
    		{
    			alert("数据项的编码需要是英文");
    			return false;
    		}
    		
    		return true;
    	}
    	
    	function doInsert()
    	{
    		location.href = "${path}/jsp/dictionary/dictionaryEdit.jsp?pId=${param.id}";
    	}
    	
    	function doSave()
    	{
    		if(doCheck())
    		{
    			var map = Form.formToBean("winForm");
        		ajax.remoteCall("com.system.dao.DictionaryDao:update",[map],function(reply){
        			var result = reply.getResult();
        			alert(result.value);
        			if(result.oprt == "save")
        			{
        				parent.updateTree(result.oprt,{id:result.id,pId:map.pId,name:map.value});
        			}
        			if(result.oprt == "edit")
        			{
        				parent.updateTree(result.oprt,{id:map.id,pId:map.pId,name:map.value});
        			}
        			
        		});
    		}
    	}
    	
    	function doDelete()
    	{
    		if(confirm("你是否确定要删除此数据项"))
  			{
  				ajax.remoteCall("com.system.dao.DictionaryDao:delete",["${param.id}"],function(reply){
  	    			var result = reply.getResult();
  	    			alert(result.value);
  	    			if(result.type == "success")
  	    			{
  	    				parent.updateTree("delete",{id:"${param.id}",pId:"${param.pId}"});
  	    			}
  	    			
  	    		});
  			}
    	}
    </script>
  </head>
  
  <body>
  	<center>	
		<div style="margin-top: 20px"></div>
		<form id="winForm" name="winForm">
			<input name="id" type="hidden" value="${param.id}">
			<input name="pId" type="hidden" value="${param.pId}">
			<fieldset style="width :98%; height: 260px; padding-left: 10px;" >
				<legend>数据项信息</legend>
				<br/>
				<table cellSpacing="0" cellPadding="0" width="100%" height="52%" border="0">
					<tr>
						<td width="120" height="30" align="right"><font color="#FF0000">*</font>&nbsp;数据项值：</td>
						<td align="left">
							<input name="value" id="value" class="textbox" style="width: 220px" />
						</td>
					</tr>
					<tr>
						<td width="120" height="30" align="right">数据项编码：</td>
						<td align="left">
							<input name="code" id="code" class="textbox" style="width: 220px"/>&nbsp;&nbsp;&nbsp;<font color="#FF0000">[使用英文并且保持唯一]</font>
						</td>
					</tr>
					<tr>
						<td width="120" height="30" style="vertical-align: top;padding-top:5px;" align="right">
							数据项备注：
						</td>
						<td align="left" style="padding-top:5px;">
							<textarea id="remark" name="remark" rows="12" cols="60" style="border-color: #6699ca"></textarea>
						</td>
					</tr>
					<tr height="120">
						<td colspan="2" align="center">
							<c:if test="${param.pId ne ''}">
								<ui:Button id="edit" type="edit" onclick="javascript:doSave();">保存</ui:Button>
							</c:if>
							
							<c:if test="${param.id ne '' && param.id ne null}">
								<c:if test="${param.pId ne ''}">
									<ui:Button id="delete" type="delete" onclick="javascript:doDelete();">删除</ui:Button>
								</c:if>
								<ui:Button id="add" type="save" onclick="javascript:doInsert();">新增子类</ui:Button>
							</c:if>
						</td>
					</tr>
				</table>
			</fieldset>	
		</form>
	</center>
  </body>
</html>